Can you please suggest me a site for learning MySQL and PHP that has proper syntax?
Because I am new to PHP/MySQL...and i am facing various syntax related issues.
User Profile
Collapse
-
Actually i have used isset() function in PHP which determines whether a variable is set and is not NULL. It returns a Boolean value, that is, if the variable is set it will return true and if the variable value is null it will return false.
But due to the above error the database is also not being created and the inserting of form data to a database is also not possible.
So could someone please suggest ways to execute the...Leave a comment:
-
Code:$sql= "INSERT INTO Persons (FirstName(30),LastName(30),Age(11)) // line 31//VALUES(if(isset('$_POST[FirstName(30)],[LastName(30)],[Age(11)]')){$notify ='$_POST([FirstName(30)],[LastName(30)],[Age(11)])'})"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } echo "1 record added"; mysqli_close($con); ?>
Leave a comment:
-
I tried the link as suggested but I am getting the error as:
( ! ) Parse error: syntax error, unexpected '(', expecting ']' in C:\wamp\www\ins ert.php on line 31
The code implemented is as :
$sql= "INSERT INTO Persons (FirstName(30), LastName(30),Ag e(11))
// line 31//VALUES(if(isset ('$_POST[FirstName(30)],[LastName(30)],[Age(11)]')){$notify ='$_POST([FirstName(30)],[LastName(30)],[Age(11)])'})";...Leave a comment:
-
-
Ok & Thanks
I have posted a new thread linked to this as :PHP script for inserting a form data to a database. Suggest Possible solution of the problem?Leave a comment:
-
The above was the insert.php file which is linked to the html form to be linked to the database.The form code is given below:
Code:<html> <body> <form action="insert.php" method="post"> Firstname: <input type="text" name="Firstname"> Lastname: <input type="text" name="Lastname"> Age: <input type="text" name="Age">
Last edited by Ankit Diwan; Jan 2 '14, 10:10 PM. Reason: ( Link to a Previous Query : Insert Data From a Form Into a Database)Leave a comment:
-
PHP script for inserting a form data to a database
Code:<?php // Connects to your Database $con = mysqli_connect("localhost", "root", "mysql@777") or die(mysqli_error()); $db_selected = mysqli_select_db($con, 'mi_db'); if (!$db_selected) { die ('Can\'t use mi_db : ' . mysqli_error()); } $sql= "INSERT INTO Persons (FirstName,LastName,Age) VALUES('$_POST[FirstName]','$_POST[LastName]','$_POST[Age]')";
-
The code is:
Code:<?php // Connects to your Database $con = mysqli_connect("localhost", "root", "mysql@777") or die(mysqli_error()); $db_selected = mysqli_select_db($con, 'mi_db'); if (!$db_selected) { die ('Can\'t use mi_db : ' . mysqli_error()); } $sql= "INSERT INTO Persons (FirstName,LastName,Age) VALUES('$_POST[FirstName]','$_POST[LastName]','$_POST[Age]')";
Leave a comment:
-
-
The proposed solution does not work. The following error was displayed:
Database mi_db created successfullyTab le persons created successfully
( ! ) Notice: Undefined index: FirstName in C:\wamp\www\ins ert.php on line 29
Call Stack
# Time Memory Function Location
1 0.0027 252088 {main}( ) ..\insert.php:0
( ! ) Notice: Undefined index: LastName in C:\wamp\www\ins ert.php on line 29
Call Stack
#...Leave a comment:
-
Insert Data From a Form Into a Database
While inserting data from a form into a database i am getting error in the below code only. The error displayed is :( ! ) Parse error: syntax error, unexpected '' (T_ENCAPSED_AND _WHITESPACE), expecting ']'
Code:$sql= "INSERT INTO Persons (FirstName,LastName,Age) VALUES('$_POST[FirstName ]','$_POST[LastName]','$_POST[Age]')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con));
-
what are you using for accessing MySQL database?Are you using SQL queries or script for the creation of database?Leave a comment:
-
Ankit Diwan replied to Connecting a MySQL database & creating & inserting values in a table via a php scriptin MySQLThere is no problem creating database mi_db but when I try to select the mi_db to create a table and to insert values into it..i get that error msg..please suggestLeave a comment:
-
Ankit Diwan replied to Connecting a MySQL database & creating & inserting values in a table via a php scriptin MySQLCode:<?php // Connects to your Database $con = mysqli_connect("localhost", "root", "mysql@777") or die(mysqli_error()); // Create Database $sql="CREATE DATABASE mi_db"; if (mysqli_query($con,$sql)) { echo "Database mi_db created successfully"; } else { echo "Error creating database: " . mysqli_error($con);
Leave a comment:
-
Ankit Diwan started a topic Connecting a MySQL database & creating & inserting values in a table via a php scriptin MySQLConnecting a MySQL database & creating & inserting values in a table via a php script
when i try to connect php script to MySQL for creating & inserting values in a table i get an error msg: Error creating database: Can't create database 'mi_db'; database existsAccess denied for user ''@'localhost' to database 'mi_db'. I am running the php via a wamp server...root directory - www and my database name is mi_db. Please suggest possible ways to resolve....
No activity results to display
Show More
Leave a comment: