Jump to content

[SOLVED] Just wont let me add?


m00ch0

Recommended Posts

I had this full script working on another webhost but now ive changed it wont work.

 

I'm hoping its in the code and someone can help me located the problem!

 

<html>

<head>

<title>Displaying MySQL Data</title>

<link href="tables.css" rel="stylesheet" type="text/css">

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

 

<style type="text/css">

<!--

body {

background-color: #6cba00;

}

.style1 {

font-family: Verdana;

color: #391D4C;

}

-->

</style>

</head>

<body>

<p>

<?php

$host="xxx"; // Host name 

$username="xxx"; // Mysql username 

$password="xxx"; // Mysql password 

$db_name="xxx"; // Database name 

$tbl_name="scontrol"; // Table name 

 

// Connect to server and select databse.

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 

mysql_select_db("$db_name")or die("cannot select DB");

 

$sql="SELECT * FROM $tbl_name ORDER BY scan ASC";

 

$result=mysql_query($sql);

 

$count=mysql_num_rows($result);

 

?>

<table align="center" width="100%" border="0" cellspacing="0" cellpadding="0">

  <tr>

    <td><table width="100%" border="0" cellspacing="3" cellpadding="0">

  <tr>

    <td><img src="logo.gif"></td>

  </tr>

</table>

</td>

  </tr>

  <tr>

    <td>

 

<form name="form1" method="post" action="">

<table border="0" cellpadding="2" cellspacing="2">

<tr>

<td width="35"  nowrap="nowrap" bgcolor="391d4c"><font color="#6cba00" size="1" face="Verdana">Scan</font></td>

<td width="250"  nowrap="nowrap" bgcolor="391d4c"><font color="#6cba00" size="1" face="Verdana">Manufacturer</font></td>

<td width="250"  nowrap="nowrap" bgcolor="391d4c"><font color="#6cba00" size="1" face="Verdana">Description </font></td>

<td  width="45"  nowrap="nowrap" bgcolor="391d4c"><font color="#6cba00" size="1" face="Verdana">Code</font></td>

<td width="200" nowrap="nowrap" bgcolor="391d4c"><font color="#6cba00" size="1" face="Verdana">Part Number</font></td>

<td width="60" nowrap="nowrap" bgcolor="391d4c" align="center"><font color="#6cba00" size="1" face="Verdana">Delete</font></td>

</tr>

<?php

while($rows=mysql_fetch_array($result)){

?>

<tr class="data">

<td><? echo $rows['scan']; ?></td>

<td><? echo $rows['manufacturer']; ?></td>

<td><? echo $rows['description']; ?></td>

<td><? echo $rows['code']; ?></td>

<td><? echo $rows['partno']; ?></td>

<td align="center"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td>

</tr>

<?php

}

?>

<tr>

<td> </td>

<td> </td>

<td> </td>

<td> </td>

<td> </td>

<td align="center"  class="data"><input name="delete" type="submit" id="delete" value="Delete"></td>

</tr>

<?php

 

if(isset($_POST['delete']))

{

foreach($_POST['checkbox'] as $row_id)

        {

                $sql = "DELETE FROM $tbl_name WHERE id='$row_id'";

                $result = mysql_query($sql);

                if($result === FALSE)

                        die("Error occured deleting row ".$row_id."!");

        }

        echo "<meta http-equiv=\"refresh\" content=\"0;URL=sc_testing_with_delete.php\">";

}

 

?>

</table>

</form>

<?php

if (!isset($_POST['submit'])) {

?>

<form action="" method="post">

<table border="0" cellpadding="2" cellspacing="2">

<tr>

<td width="35" nowrap="nowrap" bgcolor="391d4c"><font color="#6cba00" size="1" face="Verdana">Scan</font></td>

    <td width="250" nowrap="nowrap" bgcolor="391d4c"><font color="#6cba00" size="1" face="Verdana">Manufacturer</font></td>

    <td width="250" nowrap="nowrap" bgcolor="391d4c"><font color="#6cba00" size="1" face="Verdana">Description</font></td>

    <td width="45" nowrap="nowrap" bgcolor="391d4c"><font color="#6cba00" size="1" face="Verdana">Code</font></td>

    <td width="200" nowrap="nowrap" bgcolor="391d4c"><font color="#6cba00" size="1" face="Verdana">Part number</font></td>

    <td width="60" nowrap="nowrap" bgcolor="391d4c"><font color="#6cba00" size="1" face="Verdana">Submit</font></td>

</tr>

<tr class="data">

<td ><font color="#6cba00" size="1" face="Verdana"><input name="scan" type="text" size="5" maxlength="4" class="data"></font></td>

    <td><font color="#6cba00" size="1" face="Verdana"><input name="manufacturer" type="text" class="data" size="40">

    </font></td>

    <td><font color="#6cba00" size="1" face="Verdana"><input name="description" type="text" class="data" size="40">

    </font></td>

    <td><font color="#6cba00" size="1" face="Verdana"><select name="code" class="data">

  <option value="1">1</option>

  <option value="2">2</option>

  <option value="3">3</option>

  <option value="4">4</option>

  <option value="5">5</option>

  <option value="6">6</option>

  <option value="7">7</option>

  <option value="8">8</option>

  <option value="9">9</option>

</select></font></td>

    <td><font color="#6cba00" size="1" face="Verdana"><input name="partno" type="text" class="data" size="32">

    </font></td>

<td><font color="#6cba00" size="1" face="Verdana"><input type="submit" name="submit" value="Add Part" class="data">

</font></td>

</tr>

</table>

</form>

 

<?php

} else {

$scan = $_POST['scan'];

$manufacturer = $_POST['manufacturer'];

$description = $_POST['description'];

$code = $_POST['code'];

$partno = $_POST['partno'];

mysql_query("INSERT INTO `scontrol` (scan, manufacturer, description, code, partno) VALUES ('$scan', '$manufacturer', '$description', '$code', '$partno')");

echo "<br><p class=\"style1\">";

echo "The new part has been added to the database!!";

echo "<br>";

echo "<br>";

echo "<a href=\"sc_testing_with_delete.php\" title=\"Sc_testing_with_delete page\">Click here to add another part</a><br/>";

echo "</p>";

}

?>

 

</td>

  </tr>

</table>

<p> </p>

</body>

</html>

 

Full script above but I'm struggling with the below part

 

<?php

} else {

$scan = $_POST['scan'];

$manufacturer = $_POST['manufacturer'];

$description = $_POST['description'];

$code = $_POST['code'];

$partno = $_POST['partno'];

mysql_query("INSERT INTO `scontrol` (scan, manufacturer, description, code, partno) VALUES ('$scan', '$manufacturer', '$description', '$code', '$partno')");

echo "<br><p class=\"style1\">";

echo "The new part has been added to the database!!";

echo "<br>";

echo "<br>";

echo "<a href=\"sc_testing_with_delete.php\" title=\"Sc_testing_with_delete page\">Click here to add another part</a><br/>";

echo "</p>";

}

?>

 

Link to comment
https://forums.phpfreaks.com/topic/68856-solved-just-wont-let-me-add/
Share on other sites

This is the part which isn't working it suppose to add into the database but it doesn't

 

<?php

} else {

$scan = $_POST['scan'];

$manufacturer = $_POST['manufacturer'];

$description = $_POST['description'];

$code = $_POST['code'];

$partno = $_POST['partno'];

mysql_query("INSERT INTO `scontrol` (scan, manufacturer, description, code, partno) VALUES ('$scan', '$manufacturer', '$description', '$code', '$partno')");

echo "

<p class=\"style1\">";

echo "The new part has been added to the database!!";

echo "

";

echo "

";

echo "<a href=\"sc_testing_with_delete.php\" title=\"Sc_testing_with_delete page\">Click here to add another part[/url]

";

echo "</p>";

}

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.