MySQL Forums
Forum List  »  PHP

Why can't i connect to my sql database?
Posted by: Jacdonmi Bawo
Date: June 23, 2018 04:16AM

Please i have tried severally to connect to a my sql database on cpanel

I used this codes

The form code is
<form action= "insert.php" method="post">

First name: <input type="text" name="fname" id="fname"/><br><br>

Last name: <input type="text" name="lname"id="lname" /><br><br>

Gender:<input type="text" name="Gender" id="Gender"/><br><br>

<p><label>Select State:</label><select name="State"

<option value="-"selected="selected">-</option>
<option value="Abia">Abia</option>
<option value="Adamawa">Adamawa</option>
<option value="Akwaibom">Akwaibom</option>
<option value="Anambra">Anambra</option>


Lga: <input type="text" name="Lga" id="Lga"/><br><br>

<input type="submit" name="s1"id="s1"value="Submit" />




The php script in cgi folder is insert.php






$db = mysql_connect("$localhost,$lamsanng_admin ,$^^^^^^);

if (!$db)


die('Could not connect: ' . mysql_error());


mysql_select_db($lamsanng_Data ", $db);
$fname = $_POST["fname"];,
$fname= $_POST["fname"];
$Gender= $_POST["Gender"];
$Lga= $_POST["Lga"];
$State= $_POST["State"];

$query="INSERT INTO 'tbl_Jobs'";

( 'Id', 'Firstname', 'Lastname','Gender','State','Lga','submit_date')VALUES { ( '$First_name',$'Last_name,'$Gender','$State,'$Lga,'$submit_date');


if (!mysql_query($sql,$db))


die('Error: ' . mysql_error());


echo "1 record added";



The code to retrieve the stored data to my webpage is

// create short variable names

if (!$searchtype || !$searchterm) {
echo 'You have not entered search details. Please go back and try again.';

if (!get_magic_quotes_gpc()){
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);

@ $db = new mysqli('localhost', 'lamsanng_admin', '^^^^^^', 'lamsanng_Data');

if (mysqli_connect_errno()) {
echo 'Error: Could not connect to database. Please try again later.';

$query = "select * from 'tbl_Jobs' where ".$searchtype." like '%".$searchterm."%'";
$result = $db->query($query);

$num_results = $result->num_rows;

echo "<p>records found: ".$num_results."</p>";

for ($i=0; $i <$num_results; $i++) {
$row = $result->fetch_assoc();
echo "<p><strong>".($i+1).". Fname: ";
echo htmlspecialchars(stripslashes($row['Fname']));
echo "</strong><br />Lname: ";
echo stripslashes($row['Id']);
echo "</p>";



Please what is wrong with the scripts.
Thank you.^^^^^^^
is hidden password

Options: ReplyQuote

Written By
Why can't i connect to my sql database?
June 23, 2018 04:16AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.